home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / res / MessageStyles / Metal Chat 2.AdiumMessageStyle / Contents / Resources / scrolling.js < prev    next >
Encoding:
JavaScript  |  2007-11-28  |  3.2 KB  |  16 lines

  1.  
  2. var scrollToBottomIsNeeded = false;
  3. var newMsgCounter = 0;
  4. var newMsgButtonVisible = true;
  5.  
  6. function scrollToBottom() {
  7.     smoothScrollToBottom();
  8.     if (newMsgButtonVisible) {
  9.         pulsateNewMsgButton(true);
  10.         newMsgButtonVisible = false;
  11.         slideObjectBottom("newMsgButton", 0, -32, 20, 5);
  12.     }
  13.     newMsgCounter = 0;
  14. }
  15.  
  16. function checkIfScrollToBottomIsNeeded() {
  17.     scrollToBottomIsNeeded = (document.body.scrollTop >= (document.body.offsetHeight - (window.innerHeight * 1.2)));
  18.     alert("checkIfScrollToBottomIsNeeded() called with result " + scrollToBottomIsNeeded);
  19. }
  20.  
  21. function scrollToBottomIfNeeded() {
  22.     if ( scrollToBottomIsNeeded || scrolling )
  23.         scrollToBottom();
  24.     else {
  25.         newMsgCounter++;
  26.         document.getElementById("newMsgCounter").innerHTML =
  27.                                     newMsgCounter +
  28.                                     " new message" +
  29.                                     (newMsgCounter > 1 ? "s" : "");
  30.         if (!newMsgButtonVisible && newMsgCounter != 0) {
  31.             newMsgButtonVisible = true;
  32.             slideObjectBottom("newMsgButton", -32, 0, 20, 1);
  33.             pulsateNewMsgButton(true);
  34.         }
  35.     }
  36. }
  37.  
  38. var scrollID;
  39. var scrolling = false;
  40. function smoothScrollToBottom() {
  41.     if (scrolling)
  42.         window.clearInterval(scrollID);
  43.     scrolling = true;
  44.     var y0 = window.scrollY;
  45.     var y1 = document.body.offsetHeight;
  46.     var steps = 15;
  47.     var delay = 1;
  48.     var incr = (y1 - y0) / steps;
  49.     var y = y0;
  50.     scrollID = window.setInterval(function () {
  51.                     y += incr;
  52.                     if ((y0 < y1 && y1 < y) || (y0 > y1 && y1 > y)) {
  53.                         scrolling = false;
  54.                         window.clearInterval(scrollID);
  55.                     }
  56.                     else
  57.                         window.scrollTo(0, y);
  58.                 }, delay);
  59. }
  60.  
  61.  
  62. var pulsateID;
  63. var currentPulsateNum = 1;
  64. var pulsateIncr = 1;
  65. function pulsateNewMsgButton(activate) {
  66.     var obj = document.getElementById("newMsgCounter");
  67.     obj.style.backgroundImage = 'url("images/NewMsgButton/NewMessage_1.png")';
  68.     window.clearInterval(pulsateID);
  69.     
  70.     if (activate) {
  71.         currentPulsateNum = 1;
  72.         pulsateID = window.setInterval(function () {
  73.                         currentPulsateNum += pulsateIncr;
  74.                         obj.style.backgroundImage = 'url("images/NewMsgButton/NewMessage_' + currentPulsateNum + '.png")';
  75.                         if (currentPulsateNum >= 7)
  76.                             pulsateIncr = -1;
  77.                         else if (currentPulsateNum <= 1)
  78.                             pulsateIncr = 1;
  79.                     }, 100);
  80.     }
  81. }
  82.  
  83.  
  84. var slideID;
  85. function slideObjectBottom(id, start, end, steps, delay) {    
  86.    if (slideID)
  87.        window.clearInterval(slideID);
  88.    var obj = document.getElementById(id);
  89.    var incr = (end - start) / steps;
  90.    var bottom = start;
  91.    obj.style.bottom = bottom;
  92.    if (start != end)
  93.        slideID = window.setInterval(function () {
  94.                     bottom += incr;
  95.                      if ((start < end && end <= bottom) || (start > end && end >= bottom)) {
  96.                          window.clearInterval(slideID);
  97.                      }
  98.                      else
  99.                          obj.style.bottom = bottom;
  100.                  }, delay)
  101. }
  102.